//
//  XMSDemo1Controller.m
//  XMSimonUtils_Example
//
//  Created by 徐盟 on 2023/3/17.
//  Copyright © 2023 xumeng. All rights reserved.
//

#import "XMSHelperController.h"
#import "XMHelper.h"

@interface XMSHelperController ()


@end

@implementation XMSHelperController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

+ (NSArray<NSDictionary *> *)getItemDicts
{
    NSArray<NSDictionary *> * dicts = @[
        @{@"name":@"bytesToBinnaryStr", @"action": @"test1"},
        @{@"name":@"byteArrToBinnaryStr", @"action": @"test2"},
        @{@"name":@"stringFromHexString", @"action": @"test3"},
        @{@"name":@"hexStringFromString", @"action": @"test4"},
        @{@"name":@"hexStringFromData", @"action": @"test5"},
        @{@"name":@"stringFromData", @"action": @"test5"},
    ];
    
    return  dicts;
}

-(void) test1
{
    self.log(@"test1");
    long long l1 = 8;
    NSString * s1 = [XMHelper intToBinary:10];
    self.log(@"s1=%@",s1);
    
}


-(void) test2
{
    self.log(@"test2");
    Byte bb[2] = {0,128};
    
    NSString * s1 = [XMHelper byteArrToBinnaryStr:bb length:2];
    self.log(@"s1=%@",s1);
    
}

-(void) test3
{
    self.log(@"test3 stringFromHexString");
//    NSString * hexStr = @"8c4e222c22706f776572223a223838222c227364";// N","power":"88","sd
    NSString * hexStr2 = @"7b2274797065223a313030302c226e616d65223a2253696d6f6e227d";//{"type":1000,"name":"Simon"}
    NSString * hexStr3 = @"7";

    NSString * str = [XMHelper stringFromHexString: hexStr3];
    self.log(@"[1] %@", str);
//    NSString * str2 = @"abcd";
//    NSData * data = [str2 dataUsingEncoding:NSUTF8StringEncoding];
//    Byte * b2 = (Byte *)[data bytes];
//    self.log(@"[2] %x", b2[0]);
//    self.log(@"[2] %x", b2[0] & 0xff);
}

-(void) test4
{
    self.log(@"test4 hexStringFromString");

    NSString * str1 = @"{\"type\":1000,\"name\":\"Simon\"}";

    NSString * hexStr = [XMHelper hexStringFromString: str1];
    self.log(@"[1] %@", hexStr);
}

-(void) test5
{
    self.log(@"test5 hexStringFromData");

    NSString * str1 = @"{\"type\":1000,\"name\":\"Simon\"}";
    NSData * data = [str1 dataUsingEncoding:NSUTF8StringEncoding];
    self.log(@"[0] data:%@", data);
    
    NSString * hexStr = [XMHelper hexStringFromData:data];
    self.log(@"[1] hexStr:%@", hexStr);
    
    NSString * str2 = [XMHelper stringFromHexString:hexStr];
    self.log(@"[2] str2:%@", str2);
}

-(void) test6
{
    self.log(@"test6 stringFromData");

    NSString * str1 = @"{\"type\":1000,\"name\":\"Simon\"}";
    NSData * data = [str1 dataUsingEncoding:NSUTF8StringEncoding];
    self.log(@"[0] data:%@", data);
    
    NSString * str2 = [XMHelper stringFromData:data];
    self.log(@"[2] str2:%@", str2);
}

@end
